package rohyunji;

import java.awt.CardLayout;

import javax.swing.JPanel;
import java.awt.FlowLayout;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class UpdateCompany extends JPanel {
	private JTextField cp_reg_no_text;
	private JTextField cp_name_text;
	private JTextField cp_pre_text;
	private JTextField cp_addr_text;
	private JTextField cp_phone_text;
	private JTextField cp_job_type_text;
	private JTextField cp_scale_text;
	private CompanyVO cv;
	private CompanyDAO cdao;
	String cp_no=null;
	
	public UpdateCompany
	(String cp_number,CardLayout menu2AreaCard, JPanel menuArea2,final CardLayout rightCard, final JPanel right_area)
	{
		
		//DB조희 (어제했던거그대로)
		cp_no=cp_number;
		
		 cv=new CompanyVO();
	     cdao=new CompanyDAO();

		setLayout(new BorderLayout(0, 0));
		
		
		
		
		JPanel panel = new JPanel();
		add(panel);
		panel.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_5 = new JPanel();
		panel.add(panel_5, BorderLayout.CENTER);
		GridBagLayout gbl_panel_5 = new GridBagLayout();
		gbl_panel_5.columnWidths = new int[]{0, 0, 0, 80, 0};
		gbl_panel_5.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gbl_panel_5.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel_5.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
		panel_5.setLayout(gbl_panel_5);
		
		JLabel label_1 = new JLabel("기업번호");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 1;
		panel_5.add(label_1, gbc_label_1);
		
		JLabel label_2 = new JLabel("New label");
		GridBagConstraints gbc_label_2 = new GridBagConstraints();
		gbc_label_2.insets = new Insets(0, 0, 5, 0);
		gbc_label_2.gridx = 3;
		gbc_label_2.gridy = 1;
		panel_5.add(label_2, gbc_label_2);
		
		JLabel label_3 = new JLabel("회원번호");
		GridBagConstraints gbc_label_3 = new GridBagConstraints();
		gbc_label_3.insets = new Insets(0, 0, 5, 5);
		gbc_label_3.gridx = 1;
		gbc_label_3.gridy = 2;
		panel_5.add(label_3, gbc_label_3);
		
		JLabel label_4 = new JLabel("New label");
		GridBagConstraints gbc_label_4 = new GridBagConstraints();
		gbc_label_4.insets = new Insets(0, 0, 5, 0);
		gbc_label_4.gridx = 3;
		gbc_label_4.gridy = 2;
		panel_5.add(label_4, gbc_label_4);
		
		JLabel label_5 = new JLabel("사업자등록번호");
		GridBagConstraints gbc_label_5 = new GridBagConstraints();
		gbc_label_5.insets = new Insets(0, 0, 5, 5);
		gbc_label_5.gridx = 1;
		gbc_label_5.gridy = 3;
		panel_5.add(label_5, gbc_label_5);
		
		cp_reg_no_text = new JTextField();
		cp_reg_no_text.setColumns(10);
		GridBagConstraints gbc_cp_reg_no_text = new GridBagConstraints();
		gbc_cp_reg_no_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_reg_no_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_reg_no_text.gridx = 3;
		gbc_cp_reg_no_text.gridy = 3;
		panel_5.add(cp_reg_no_text, gbc_cp_reg_no_text);
		
		JLabel label_6 = new JLabel("기업명");
		GridBagConstraints gbc_label_6 = new GridBagConstraints();
		gbc_label_6.insets = new Insets(0, 0, 5, 5);
		gbc_label_6.gridx = 1;
		gbc_label_6.gridy = 4;
		panel_5.add(label_6, gbc_label_6);
		
		cp_name_text = new JTextField();
		cp_name_text.setColumns(10);
		GridBagConstraints gbc_cp_name_text = new GridBagConstraints();
		gbc_cp_name_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_name_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_name_text.gridx = 3;
		gbc_cp_name_text.gridy = 4;
		panel_5.add(cp_name_text, gbc_cp_name_text);
		
		JLabel label_7 = new JLabel("대표자명");
		GridBagConstraints gbc_label_7 = new GridBagConstraints();
		gbc_label_7.insets = new Insets(0, 0, 5, 5);
		gbc_label_7.gridx = 1;
		gbc_label_7.gridy = 5;
		panel_5.add(label_7, gbc_label_7);
		
		cp_pre_text = new JTextField();
		cp_pre_text.setColumns(10);
		GridBagConstraints gbc_cp_pre_text = new GridBagConstraints();
		gbc_cp_pre_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_pre_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_pre_text.gridx = 3;
		gbc_cp_pre_text.gridy = 5;
		panel_5.add(cp_pre_text, gbc_cp_pre_text);
		
		JLabel label_8 = new JLabel("주소");
		GridBagConstraints gbc_label_8 = new GridBagConstraints();
		gbc_label_8.insets = new Insets(0, 0, 5, 5);
		gbc_label_8.gridx = 1;
		gbc_label_8.gridy = 6;
		panel_5.add(label_8, gbc_label_8);
		
		cp_addr_text = new JTextField();
		cp_addr_text.setColumns(10);
		GridBagConstraints gbc_cp_addr_text = new GridBagConstraints();
		gbc_cp_addr_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_addr_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_addr_text.gridx = 3;
		gbc_cp_addr_text.gridy = 6;
		panel_5.add(cp_addr_text, gbc_cp_addr_text);
		
		JLabel label_9 = new JLabel("연락처");
		GridBagConstraints gbc_label_9 = new GridBagConstraints();
		gbc_label_9.insets = new Insets(0, 0, 5, 5);
		gbc_label_9.gridx = 1;
		gbc_label_9.gridy = 7;
		panel_5.add(label_9, gbc_label_9);
		
		cp_phone_text = new JTextField();
		cp_phone_text.setColumns(10);
		GridBagConstraints gbc_cp_phone_text = new GridBagConstraints();
		gbc_cp_phone_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_phone_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_phone_text.gridx = 3;
		gbc_cp_phone_text.gridy = 7;
		panel_5.add(cp_phone_text, gbc_cp_phone_text);
		
		JLabel label_10 = new JLabel("직종");
		GridBagConstraints gbc_label_10 = new GridBagConstraints();
		gbc_label_10.insets = new Insets(0, 0, 5, 5);
		gbc_label_10.gridx = 1;
		gbc_label_10.gridy = 8;
		panel_5.add(label_10, gbc_label_10);
		
		cp_job_type_text = new JTextField();
		cp_job_type_text.setColumns(10);
		GridBagConstraints gbc_cp_job_type_text = new GridBagConstraints();
		gbc_cp_job_type_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_job_type_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_job_type_text.gridx = 3;
		gbc_cp_job_type_text.gridy = 8;
		panel_5.add(cp_job_type_text, gbc_cp_job_type_text);
		
		JLabel label_11 = new JLabel("규모");
		GridBagConstraints gbc_label_11 = new GridBagConstraints();
		gbc_label_11.insets = new Insets(0, 0, 5, 5);
		gbc_label_11.gridx = 1;
		gbc_label_11.gridy = 9;
		panel_5.add(label_11, gbc_label_11);
		
		cp_scale_text = new JTextField();
		cp_scale_text.setColumns(10);
		GridBagConstraints gbc_cp_scale_text = new GridBagConstraints();
		gbc_cp_scale_text.fill = GridBagConstraints.HORIZONTAL;
		gbc_cp_scale_text.insets = new Insets(0, 0, 5, 0);
		gbc_cp_scale_text.gridx = 3;
		gbc_cp_scale_text.gridy = 9;
		panel_5.add(cp_scale_text, gbc_cp_scale_text);
		
		JLabel label_12 = new JLabel("사업규모");
		GridBagConstraints gbc_label_12 = new GridBagConstraints();
		gbc_label_12.insets = new Insets(0, 0, 5, 5);
		gbc_label_12.gridx = 1;
		gbc_label_12.gridy = 10;
		panel_5.add(label_12, gbc_label_12);
		
		final JTextArea cp_content_lbl = new JTextArea();
		GridBagConstraints gbc_cp_content_lbl = new GridBagConstraints();
		gbc_cp_content_lbl.fill = GridBagConstraints.BOTH;
		gbc_cp_content_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_content_lbl.gridx = 3;
		gbc_cp_content_lbl.gridy = 10;
		panel_5.add(cp_content_lbl, gbc_cp_content_lbl);
		
		JLabel label_13 = new JLabel("설립일");
		GridBagConstraints gbc_label_13 = new GridBagConstraints();
		gbc_label_13.insets = new Insets(0, 0, 0, 5);
		gbc_label_13.gridx = 1;
		gbc_label_13.gridy = 11;
		panel_5.add(label_13, gbc_label_13);
		
		final JLabel cp_incor_day_lbl = new JLabel("New label");
		GridBagConstraints gbc_cp_incor_day_lbl = new GridBagConstraints();
		gbc_cp_incor_day_lbl.gridx = 3;
		gbc_cp_incor_day_lbl.gridy = 11;
		panel_5.add(cp_incor_day_lbl, gbc_cp_incor_day_lbl);
		
		JPanel panel_4 = new JPanel();
		panel.add(panel_4, BorderLayout.WEST);
		panel_4.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_3 = new JPanel();
		panel.add(panel_3, BorderLayout.EAST);
		
		JPanel panel_2 = new JPanel();
		panel.add(panel_2, BorderLayout.NORTH);
		
		JLabel label = new JLabel("기업정보수정");
		panel_2.add(label);
		
		JPanel panel_1 = new JPanel();
		panel.add(panel_1, BorderLayout.SOUTH);
		panel_1.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		
		//수정할데이터불러오기 시작
		
		cv.setCp_no(cp_no);
		
	
		
		//조회
		for(CompanyVO v2:cdao.SelectCompany(cv))
		{
								
			cp_reg_no_text.setText(v2.getCp_reg_no());
	
			
			
			cp_name_text.setText(v2.getCp_name());
			cp_pre_text.setText(v2.getCp_pre());
			cp_addr_text.setText(v2.getCp_addr());
			cp_phone_text.setText(v2.getCp_phone());
			cp_job_type_text.setText(v2.getCp_job_type());
			cp_scale_text.setText(v2.getCp_scale());
			cp_content_lbl.setText(v2.getCp_content());
			cp_incor_day_lbl.setText(v2.getCp_incor_day());
			
			
		}
		//수정할데이터불러오기 끝
		
		JButton button = new JButton("수정하시겠습니까");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			
				
				
				//수정을 등록할때처럼DB수정등록
				
				cv.setCp_no(cp_no);
				cv.setCp_reg_no(cp_reg_no_text.getText());
				cv.setCp_name(cp_name_text.getText());
			
				cv.setCp_pre(cp_pre_text.getText());
				cv.setCp_addr(cp_addr_text.getText());
				cv.setCp_phone(cp_phone_text.getText());
				cv.setCp_job_type(cp_job_type_text.getText());
				cv.setCp_scale(cp_scale_text.getText());
				cv.setCp_content(cp_content_lbl.getText());
			
	
				if(cdao.UpdateCompany(cv)){
					System.out.println("등록 되었습니다");}
				else System.out.println("등록실패 하였습니다");
				
				
			}
		});
		panel_1.add(button);
		
		JButton button_1 = new JButton("확인");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				rightCard.show(right_area,"cp_read");
			}
		});
		panel_1.add(button_1);
		
		
		
		// TODO Auto-generated constructor stub

	
	}

}
